package com.sky.controller.admin;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.dto.UpdateSetmealDto;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ISetmealService;
import com.sky.vo.SetmealVO;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 套餐 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-07-02
 */
@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐")
public class SetmealController {

    @Autowired
    private ISetmealService service;

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result page(SetmealPageQueryDTO dto){
        PageResult pageResult=   service.getPage(dto);
        return Result.success(pageResult);
    }
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result selectById(@PathVariable Long id){
       SetmealVO setmealVO= service.getSeatmealById(id);
         return Result.success(setmealVO);
    }

    @PutMapping
    public Result updateSetmealById(@RequestBody UpdateSetmealDto dto){
        service.updateSetmeal(dto);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    public Result updateStatusById(Long id,@PathVariable Integer status){
        service.updateSetmeal(id,status);
        return Result.success();
    }

    @DeleteMapping
    public Result deleteByIds(@RequestParam("ids") List<Integer> ids){
        service.removeByIds(ids);
        return Result.success();
    }

}
